package com.winter.controller;

/**
 * Created by lenovo on 2016/12/6.
 */
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@EnableAutoConfiguration
public class StringRedisController {

    protected static Logger logger=LoggerFactory.getLogger(StringRedisController.class);

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @Resource(name="stringRedisTemplate")
    ValueOperations<String,String> valOpsStr;

    @RequestMapping("/set")
    public String setKeyAndValue(String key,String value){
        logger.debug("访问set:key={},value={}",key,value);
        valOpsStr.set(key, value);
        return "Set Ok";
    }

    @RequestMapping("/get")
    @ResponseBody
    public String getKey(String key){
        logger.debug("访问get:key={}",key);
        return valOpsStr.get(key);
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(StringRedisController.class, args);
    }
}
